<?php


namespace App\Services\PosApi;

use D1M\Payment\Models\Payment as PaymentModel;
use D1M\Payment\Models\CombinedPayment as CombinedPaymentModel;
class Payment
{
    public $payStatus = [
        'created' => 'NOTPAY',
        'error_occurred' => 'PAYMENT',
        'paying' => 'PAYMENT',
        'paid' => 'SUCCESS',
        'failed' => 'FAILED'
    ];

    public function getResult($id)
    {
        $combinedInfo = CombinedPaymentModel::where('id', $id)->first();
        if (empty($combinedInfo))
            return ['error' => true, 'message' => '组合支付单不存在'];
        $payment = PaymentModel::where('combined_payment_id', $id)->where('batch', $combinedInfo->batch)->first();

        return empty($payment) ? ['error' => false, 'data' => [
            'payment_method' => 'null',
            'status' => $this->payStatus[$combinedInfo->status]
        ]] : ['error' => false, 'data' => [
            'payment_method' => $payment->payment_method,
            'status' => $this->payStatus[$payment->status]
        ]];
    }
}